<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width" />
    <meta name="format-detection" content="telephone=no" />
    <title>进站派单详情</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" href="../script/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../script/agile/css/flat/flat.color.css">
    <link rel="stylesheet" type="text/css" href="../css/standBillRevertDetail.css" />
    <style>

    </style>
</head>

<body>
    <!--下拉列表-->
    <script id="dict-template" type="text/x-dot-template">
        {{ for(var i=0, len=it.length; i
        < len; i++) {}} <option value="{{=it[i].itemvalue}}">{{=it[i].itemname}}</option>

            {{ } }}
    </script>

    <script id="option-template" type="text/x-dot-template">
        {{ for(var i=0, len=it.length; i
        < len; i++) {}} <option value="{{=it[i].orgid}}">{{=it[i].orgname}}</option>

            {{ } }}
    </script>
    <script id="station-option" type="text/x-dot-template">
        {{ for(var i=0, len=it.length; i
        < len; i++) {}} <option value="{{=it[i].st_id}}">{{=it[i].st_name}}</option>

            {{ } }}
    </script>
    <div id="wrap">
        <div id="billDetailDivId" style="overflow:auto;margin-bottom:55px;">
            <div class="cardDiv">
                <div class="cardLabel">选择的站址：</div>
                <div class="cardCon">
                    <input id="stationNameId" type="text" readonly="readonly" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;">
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">进站人：</div>
                <div class="cardCon">
                    <input id="standPersonId" type="text" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;">
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">联系电话：</div>
                <div class="cardCon">
                    <input id="contactTeleId" type="number" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;">
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">进站人单位：</div>
                <div class="cardCon">
                    <select id="standDepId" name="company" style="background-color:#FFFFFF;width:100%;height:100%;font-size:14px;" value="">
        				<option value="1001">移动</option>
        				<option value="1002">联通</option>
        				<option value="1003">电信</option>
        				<option value="1004">铁塔</option>
        				<option value="OTHER">其它</option>
    				</select>
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">上站原因：</div>
                <div class="cardCon">
                    <select id="standCauseId" style="background-color:#FFFFFF;width:100%;height:100%;font-size:14px;">
                        <option>请选择</option>
                        <option value="2">故障处理</option>
                				<option value="3">施工勘察</option>
                				<option value="5">日常巡检</option>
                        <option value="6">应急发电</option>
                        <option value="7">工程验收</option>
    				        </select>
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">紧急程度：</div>
                <div class="cardCon">
                    <select id="degreeId" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;font-size:14px;">
                      <option>请选择</option>
                        <option value="1">紧急</option>
                        <option value="2">一般</option>
                    </select>
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">申请进站时间：</div>
                <div class="cardCon">
                    <input id="applyStandDateId" type="datetime-local" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;">
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">申请离站时间：</div>
                <div class="cardCon">
                    <input id="applyOutStandId" type="datetime-local" style="background-color:#FFFFFF;width:100%;height:100%;line-height:40px;">
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">是否需要随工：</div>
                <div class="cardCon">
                    <select id="applyIsNeedPersonId" style="background-color:#FFFFFF;width:100%;height:100%;font-size:14px;" value="">
        				<option value="Y">是</option>
        				<option value="N">否</option>
    				</select>
                </div>
            </div>
            <div class="cardDiv">
                <div class="cardLabel">
                    <div class="cardLabelTop">开门是否判断&nbsp;&nbsp;</div>
                    <div class="cardLabelDown">经纬度：</div>
                </div>
                <div class="cardCon">
                    <select id="openDoorIsLatId" style="background-color:#FFFFFF;width:100%;height:100%;font-size:14px;" value="">
        				<option value="N">否</option>
        				<option value="Y">是</option>
    				</select>
                </div>
            </div>


            <div id="refiefDealInfoDivId" class="cardTextareaDiv">
                <div class="cardTextareaLabel">备注：</div>
                <div class="cardTextareaCon">
                    <textarea id="remarkId" rows="8" class="noborder" style="background-color:white;border:solid 1px green;width:100%;height:100%;"></textarea>
                </div>
            </div>
        </div>
        <footer style="height:50px;">
            <div class="cardButtonDiv">
                <button class="cancelBtn" onclick="closeWin()">取消</button>
                <button class="okBtn" onclick="creatBillOpt()">派单</button>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/constant.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/client.api.js"></script>
<script type="text/javascript" src="../script/aui-alert.js"></script>
<script src="../script/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../script/home_frm.js"></script>
<script>
    apiready = function() {
        //status bar style
        api.setStatusBarStyle({
            style: 'light'
        });
        var tdObj = $api.byId("stationNameId");
        tdObj.value = api.pageParam.stationName;

        initDict();
        initDict2();

        //  var standCompanyList=$api.getStorage("standCompany");
        //  $('<option>').text('请选择').val('').appendTo('#standDepId');
        //	renderTemp('cityid', 'dict-template', standCompanyList, true);
    };

    function initDict2() {
        var user = $api.getStorage("user"); //进站人单位
        var standCompanyList = $api.getStorage("standCompanyList"); //进站人单位
        var upstationList = $api.getStorage("upstationList"); //上站原因
        console.log('==================================================----');
        console.log(upstationList);
        console.log(getObj(user));
        for (var i = 0; i < upstationList.length; i++) {
          console.log(getObj(upstationList[i]));
        }

        if (standCompanyList != null && standCompanyList.length > 0) {
            //     alert("集合数："+standCompanyList.length);
            $('#standDepId').empty();
            $('<option>').text('请选择').val('').appendTo('#standDepId');
            renderTemp('standDepId', 'dict-template', standCompanyList, true);
        }

        if (upstationList != null && upstationList.length > 0) {
            //     alert("集合数："+upstationList.length);
            $('#standCauseId').empty();
            $('<option>').text('请选择').val('').appendTo('#standCauseId');
            renderTemp('standCauseId', 'dict-template', upstationList, true);   //此处控制上站单页面 上站原因一栏
        }

        console.log("用户id：" + user.leaderid);

        if ("1001" == user.leaderid) {
            $('[name=company]').val('1001')
        } else if ("1002" == user.leaderid) {
            $('[name=company]').val('1002')
        } else if ("1003" == user.leaderid) {
            $('[name=company]').val('1003')
        } else if ("1004" == user.leaderid) {
            $('[name=company]').val('1004')
        }

    }

    function creatBillOpt() {
        var user = $api.getStorage('user');
        var userId = user.userid;
        var standPerson = $api.byId("standPersonId").value;
        var applyStandDate = $api.byId("applyStandDateId").value;
        var applyoffsitedate = $api.byId("applyOutStandId").value;
        var applyIsNeedPerson = $api.byId("applyIsNeedPersonId").value;
        var contactTele = $api.byId("contactTeleId").value;
        var standCause = $api.byId("standCauseId").value;
        // wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        var degree = $api.byId('degreeId').value;
        // wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        var company = $api.byId("standDepId").value;
        var remark = $api.byId("remarkId").value;
        var openDoorIsLat = $api.byId("openDoorIsLatId").value;
        if (!standPerson) {
            api.toast({
                msg: "请填写进站人员",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!contactTele) {
            api.toast({
                msg: "请填写联系电话",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!company) {
            api.toast({
                msg: "请选择进站人单位",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!standCause) {
            api.toast({
                msg: "请选择上站原因",
                duration: 1000,
                location: 'middle'
            });
            return;
        }

        if (!degree) {
            api.toast({
                msg: "请选择紧急程度",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!applyStandDate) {
            api.toast({
                msg: "请选择申请进站时间",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!applyoffsitedate) {
            api.toast({
                msg: "请选择申请离站时间",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        if (!applyIsNeedPerson) {
            api.toast({
                msg: "请选择是否需要随工",
                duration: 1000,
                location: 'middle'
            });
            return;
        }
        var paramJson = {};
        paramJson.userid = userId;
        paramJson.stationid = api.pageParam.stationId;
        paramJson.contactperson = standPerson;
        paramJson.applystanddate = applyStandDate.replace(/T/, " ") + ":00";
        paramJson.applyoffsitedate = applyoffsitedate.replace(/T/, " ") + ":00";
        paramJson.applyisneedperson = applyIsNeedPerson;
        paramJson.contactphone = contactTele;
        paramJson.cause = standCause;
        // wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        paramJson.degree = degree;
        // wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        paramJson.company = company;
        paramJson.remark = remark;
        paramJson.openDoorIsLat = openDoorIsLat;
        paramJson.dealobject=user.leaderid;
        api.closeWin({
            name: "createBillSelStation"
        });
        api.showProgress({
            title: '加载中',
            modal: false
        });
        console.log(paramJson);
        console.log(getObj(paramJson));

        $client.createStandBill(paramJson, function(ret, err) {
            if (ret) {
                if (ret.success) {
                    api.toast({
                        msg: "派单成功",
                        duration: 800,
                        location: 'middle'
                    });
                    window.setTimeout(function() {
                        closeWin();
                    }, 900);
                } else {
                    api.toast({
                        msg: ret.data_info,
                        location: 'middle'
                    });
                }
            } else {
                api.toast({
                    msg: err.msg,
                    location: 'middle'
                });
            }
            api.hideProgress();
        });
    }

    function closeWin() {
        api.closeWin({
            name: 'createStandBill'
        });
    }
</script>

</html>
